package com.link.base.base.appduty.controller;

import com.link.base.base.appduty.model.AppSecurityMenu;
import com.link.base.base.appduty.service.AppSecurityMenuService;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.model.BasicModel;
import com.link.core.basic.query.Filter;
import com.link.core.basic.query.QueryParams;
import com.link.core.basic.service.BasicService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Copyright  hande Company. All Rights Reserved.
 *
 * @author unknwon
 * @version 1.0
 * @date: 2018/11/8 13:48
 */

@Controller
@RequestMapping("/link/appSecurityMenu")
public class AppSecurityMenuController extends BasicController<AppSecurityMenu> {

    @Resource
    private AppSecurityMenuService appSecurityMenuService;

    @Override
    public BasicService<AppSecurityMenu> getBasicService() throws Exception {
        return appSecurityMenuService;
    }

    /**
     * @return
     * @author lizt
     * 查询未选择的安全性菜单
     */
    @RequestMapping(value = "/unSelectSubMenuList", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> unSelectSubMenuList(String menuId, String interId, @JsonParam QueryParams qps,
                                                   HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        List<AppSecurityMenu> list = null;
        try {
            qps.setAttr1(interId);
            qps.addFilter(new Filter("parentId", menuId));
            AppSecurityMenu t = (AppSecurityMenu) BasicModel.transformClass(AppSecurityMenu.class, qps);
            list = appSecurityMenuService.queryUnSelectSubMenuListPage(t);
            result.put("success", true);
            result.put("rows", list);
            result.put("total", getCount((BasicModel) t, list.size()));
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
